package com.ruoyi.project.his.controller;


import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.his.domain.DrugInfo;
import com.ruoyi.project.his.service.IdrugInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api("查询药品信息管理")
@RestController
@RequestMapping("/drug/info")
public class DrugInfoController extends BaseController {
    @Autowired
    private IdrugInfoService drugInfoService;

    /**
     * 查询药品信息维护
     */
    @ApiOperation("查询药品信息维护")
    @GetMapping("/list")
    public TableDataInfo list(DrugInfo drugInfo) {
        startPage();
        List<DrugInfo> list = drugInfoService.selectDrugInfoList(drugInfo);
        return getDataTable(list);
    }

    /**
     * 查询单个生产厂家维护信息(用于修改回显)
     */
    @ApiOperation("查询单个生产厂家维护信息信息")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return AjaxResult.success(drugInfoService.selectDrugInfoById(id));
    }

    /**
     * 新增生产药品维护信息
     *
     * @param drugInfo
     * @return
     */
    @ApiOperation("新增生产药品维护信息")
    @Log(title = "新增生产药品维护信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody DrugInfo drugInfo) {
        drugInfo.setCreateBy(SecurityUtils.getUsername());
        drugInfo.setCreateTime(DateUtils.getNowDate());
        drugInfo.setIsDelete("1");
        return toAjax(drugInfoService.insertDrugInfo(drugInfo));
    }

    /**
     * 修改生产药品维护信息
     */
    @ApiOperation("修改生产药品维护信息")
    @Log(title = "修改生产药品维护信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DrugInfo drugInfo) {
        drugInfo.setUpdateBy(SecurityUtils.getUsername());
        drugInfo.setUpdateTime(DateUtils.getNowDate());
        return toAjax(drugInfoService.updateDrugInfo(drugInfo));
    }

    /**
     * (虚假)删除药品信息维护的一条
     */
    @ApiOperation("删除药品信息维护的一条")
    @Log(title = "删除药品信息维护的一条", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(drugInfoService.deleteDrugInfoByIds(ids));
    }

    /**
     * 修改药品状态
     * @param id
     * @param status
     * @return
     */
    @ApiOperation("修改药品状态")
    @Log(title = "修改药品状态", businessType = BusinessType.UPDATE)
    @PutMapping(value = "/{id}/{status}")
    public AjaxResult editState(@PathVariable("id") String id, @PathVariable("status") String status) {
        return toAjax(drugInfoService.updateDrugInfoState(id, status));
    }
}
